from dataclasses import dataclass
from typing import Optional
from flask import request, make_response, Blueprint, send_from_directory
from sqlalchemy import Connection, text, Engine

BP_local_test = Blueprint("BP_local_test", __name__, url_prefix="/local_test")
LOCAL_TEST = False
API_ROOT = "http://localhost:38828"

engine: Engine
def make_engine(debug: bool):   
    from sqlalchemy import create_engine
    engine_path = (
        "postgresql://Administrator@localhost/jwtest"
        if debug
        else "postgresql://jw238:123123@localhost/main"
    )
    print(f"[engine use] {engine_path}")
    engine: Engine = create_engine(engine_path)
    return engine

def init(debug: bool):
    global engine
    engine = make_engine(debug)

@BP_local_test.route("/<path:path>", methods=["GET"])
def local_test(path):
    # path = "/" + path
    print("[local_test]: ", path)
    return send_from_directory("E:/1-code/visdata/root", path)